package utils;

import haxe.Json;
import js.Browser;

class SaveData {
	/**
	 * 将数据储存到本地
	 * @param key 
	 * @param value 
	 */
	public static function setItem(key:String, value:Dynamic):Void {
		trace("setItem", key, value);
		Browser.getLocalStorage().setItem(key, Json.stringify(value));
	}

	/**
	 * 读取本地数据
	 * @param key 
	 * @return Dynamic
	 */
	public static function getItem(key:String, defaultValue:Dynamic):Dynamic {
		var value = Browser.getLocalStorage().getItem(key);
		trace("getItem", key, value);
		if (value == null) {
			return defaultValue;
		}
		return Json.parse(value);
	}
}